package com.example.springvue.mapper;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springvue.model.AuthGroup;
import com.example.springvue.model.AuthRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface AuthRuleMapper extends BaseMapper<AuthRule> {


    //获取一级菜单
    @Select(
            {"<script>",
                    "SELECT id,pid,url as path,title,icon,component,is_menu as isShow FROM auth_rule",
                    "WHERE pid = 0",
                    "AND  is_menu = 1",
                    "<when test='Id!=null'>",
                    "AND id in (#{Id})",
                    "</when>",
                    "</script>"}
            )
    List<Map< String, Object >> getAuthRuleList(String Id);

    //获取子集菜单
    @Select(
            {"<script>",
                    "SELECT id,pid,url as path,title,icon,component,is_menu as isShow FROM auth_rule",
                    "WHERE is_menu = 1",
                    "and pid = #{Id}",
                    "</script>"}
    )
    List<Map< String, Object >> getAuthRuleListTwo(String Id);



    //获取所有一级菜单
    @Select(
            {"<script>",
                    "SELECT * FROM auth_rule",
                    "WHERE pid = 0",
                    "</script>"}
    )
    List<Map< String, Object >> getAuthRule();

    //获取所有一级菜单
    @Select(
            {"<script>",
                    "SELECT * FROM auth_rule",
                    "WHERE pid =  #{Id}",
                    "</script>"}
    )
    List<Map< String, Object >> getAuthRuleTwo(String Id);


    //删除
    @Select(
            {"<script>",
                    "DELETE FROM auth_rule",
                    "WHERE id =  #{Id}",
                    "</script>"}
    )
    Integer authRuleDelete(String Id);

}
